<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-07-24 11:31
 *
 * Version: 2.0
 */

namespace App\Lib\Notices;


use App\Lib\Contracts\Notices;
use Illuminate\Support\Facades\Log;
use JPush\Client as JPush;
class JPushNotices implements Notices
{
	private $client;

	public function __construct()
	{
		$this->client  = new JPush(env('J_PUSH_APP_KEY'),env('J_PUSH_APP_SECRET'),env('J_PUSH_APP_LOGFILE'));
	}

	public function sendNotice($userIds,$message=null,$sound='default',$title=null,$content=null)
	{
		return $this->client->push()
			//设置发送的平台
			->setPlatform(array('ios', 'android'))
			//别名，用于推送到指定用户
			->addalias((string)$userIds)
			//设置给ios平台推送的数据
			->iosNotification($message['message']['content'], array(
				"badge" => '1',
				"content-available" => true,
				"mutable-content" => true,
				"extras" => $message,
				'sound' => isset($message['sound']) ? $message['sound'] : 'default'
			))
			//设置android平台推送
			->androidNotification($message['message']['content'], array(
//				'title' => isset($message['title']) ? $message['title'] : (isset($title) ? $title : "测试"),
				'extras'=> $message,
			))
			->options(array(
				//设置推送环境是开发环境 or 运营模式（上线模式）
				'apns_production' => env('J_PUSH_PRODUCTION'),
			))
			//执行推送
			->send();
	}


//	public static function makeParams($message,$title=null,$content=null){
//		return [
//				'id' => isset($message['id']) ? $message['id'] : rand(1,10000),
//				'sub_type' => isset($message['sub_type']) ? $message['sub_type'] :rand(1,10000),
//				'title' => isset($message['title']) ? $message['title'] : (isset($title) ? $title : "测试"),
//				'content' => isset($message['content']) ? $message['content'] : (isset($content) ? $content : "测试"),
//				'time' => date('Y-m-d H:i:s',time())
//		];
//	}
}

